package com.blog1.controller;

import com.blog1.pojo.request.AddBlogInfo;
import com.blog1.pojo.request.UpdateBlogRequest;
import com.blog1.pojo.response.BlogInfoListResult;
import com.blog1.pojo.response.BlogInfoResult;
import com.blog1.service.BlogInfoService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/blog")
public class BlogController {

    @Resource(name = "blogInfoServiceImpl")
    private BlogInfoService blogInfoService;

@RequestMapping("/getList")
    public List<BlogInfoListResult>getList(){
log.info("获取博客列表");
List<BlogInfoListResult> blogInfos=blogInfoService.getList();
return blogInfos;
    }

    @RequestMapping("/getBlogDetail")
public BlogInfoResult getBlogDetail(@NotNull Integer blogId){
    log.info("获取博客详情");
    BlogInfoResult blogInfoResult=blogInfoService.getBlogDetail(blogId);
    return blogInfoResult;
    }

    @RequestMapping("/add")
public Boolean addBlog(@RequestBody @Validated AddBlogInfo addBlogInfo){
    log.info("添加博客, userId:{},title:{}",addBlogInfo.getUserId(),addBlogInfo.getTitle());
    return blogInfoService.addBlog(addBlogInfo);
    }

    @RequestMapping("/update")
    public Boolean updateBlog(@RequestBody @Validated UpdateBlogRequest updateBlogRequest){
log.info("更新博客, blogId:{},title:{}",updateBlogRequest.getId(),updateBlogRequest.getTitle());
return blogInfoService.updateBlog(updateBlogRequest);
    }

    @RequestMapping("/delete")
public Boolean deleteBlog(@NotNull Integer blogId){
log.info("删除博客, blogId:{}",blogId);
return blogInfoService.deleteBlog(blogId);
    }


}
